/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package org.oimwrapper.testers;

import Thor.API.Operations.tcFormDefinitionOperationsIntf;
import Thor.API.Operations.tcFormInstanceOperationsIntf;
import Thor.API.Operations.tcObjectOperationsIntf;
import com.thortech.util.logging.Logger;
import java.util.Map;
import org.junit.Test;
import org.oimwrapper.connectors.OIMAdapterBase;
import org.oimwrapper.connectors.OIMRemoteClientBase;
import org.oimwrapper.connectors.internal.OIMFormUtilities;
import org.oimwrapper.connectors.internal.OIMUtilityGetter;

/**
 *
 */
public class ClientFormsTester {

    private static final Logger logger = Logger.getLogger(ClientFormsTester.class.getName());

    private OIMAdapterBase apiBase;

    @Test
    public void mainTest()
    {
        logger.debug("Starting ");
        OIMRemoteClientBase tester = null;
        logger.debug("Logging In ");
        try {
            tester = new OIMRemoteClientBase();

            System.setProperty("XL.HomeDir", TesterConfig.XL_HomeDir);
            tester.setConnectionInfo(TesterConfig.XL_USERID);
            tester.connect();
            apiBase = tester.getUtils();
        } catch (Exception ex) {
            logger.error("Exception",ex);
            return;
        }

        logger.debug("Logged In! ");

        String childTable = "UD_RESB_CP";
        long ik = 6943l;
        
        tcFormInstanceOperationsIntf formInstOps = null;
        tcFormDefinitionOperationsIntf formDefOps = null;
        tcObjectOperationsIntf objectOp = null;
        
        try
        {
            formInstOps = (tcFormInstanceOperationsIntf)apiBase.getUtility(Thor.API.Operations.tcFormInstanceOperationsIntf.class);
            formDefOps = (tcFormDefinitionOperationsIntf)apiBase.getUtility(Thor.API.Operations.tcFormDefinitionOperationsIntf.class);
            objectOp = (tcObjectOperationsIntf)apiBase.getUtility(Thor.API.Operations.tcObjectOperationsIntf.class);
        }
        catch(Exception e)
        {
            
        }
        
        OIMFormUtilities formUtils = OIMUtilityGetter.getFormUtilities(logger, formDefOps, formInstOps);

        try {
            Map rec = formUtils.getProcessFormValues(ik,false,null);
            //formUtils.getProcessFormValues(ik, true, null);
            logger.debug("PI Form Data " + rec);
            Map[] recs = formUtils.getProcessFormChildValues(ik, childTable, false, null);

            logger.info("Parent Rec " + rec);
            if (recs != null && recs.length > 0) {
                for (int i = 0; i < recs.length; i++) {
                    logger.info("Rec " + recs[i]);
                }
            }
        } catch (Exception e) {
            logger.error("Error", e);
        }
    }

}
